import util from 'common/js/util'
import config from 'common/js/config'
import popup from 'popup'
require('common/js/jquery.cookie.js')
// 设置背景色
var bg=require('common/images/login-bg.png')
$('#html').css({background:`url(${bg}`})
var redirecturl = util.getQueryString('redirecturl');

var app = new Vue({
    el: '#login',
    data: {
        openid:'',
        pwd:'',
    },
    mounted() {
        this.$nextTick(()=>{
            document.onkeydown =(event=>{
                var e = event || window.event || arguments.callee.caller.arguments[0];
                if (e && e.keyCode == 13) { // enter 键
                    this.logingoing();
                }
            });
        })
    },
    methods: {
        // 登录
        logingoing(){
            if(!util.regCombination('*').test(this.openid)){
                popup.alert({title:'请填写用户名'}); return false;
            }
            if(!util.regCombination('*').test(this.pwd)){
                popup.alert({title:'请填写密码'}); return false;
            }
            util.ajax({
                url:config.baseApi+'game-manage/api/auth/login',
                data:{
                    openid:this.openid,
                    pwd:this.pwd,
                    accountType:0,
                },
                success:(data=>{
                    if (data.data) {
                        // if(location.host.includes('127.0.0.1')||location.host.includes('test-newhope')){
                            $.cookie('gameToken', data.data, {
                                path: '/',
                            })
                        // }
                    };
                    if(redirecturl){
                        location.href = "/#/?redirecturl="+encodeURIComponent(redirecturl);
                    }else{
                        location.href = "/#/"
                    }
                })
            })
        },
    }
})


 
